#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QComboBox>
#include <QHBoxLayout>
#include <tuple>
#include <QMenu>
#include "newwidget.h"
#include "Robot.h"
#include "connecter.h"
#include <QtSerialPort/QSerialPortInfo>
#include "FrameBase.h"
#include "QVector"
#include "demonstratewidget.h"
#include "programControl.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE


struct JointsCAN
{
    uint32_t jntSendId;
    uint32_t jntReceId;
    uint32_t jntReceMask;
    FrameSize jntSendIdSize;
    FrameSize jntReceIdSize;
};



class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void addSendFrame();
    void removeSendFrame();
    void addReceiveFrame();
    void removeReceiveFrame();
    void addJoint();
    void removeJoint();

private:
    Ui::MainWindow *ui;
    Robot robot;

    void reloadInformationOfRobot();

    canCont::CAN_Connecter* canConnecter;
    JointsCAN jntCAN[6];
    ProgramControl* pgmCtrl;
    QSerialPort* serial;
    vector<QComboBox*> sendFilters;
    vector<QComboBox*> receiveFilters;
    void closeEvent(QCloseEvent *event);



/* @brief DataSave_t: the constructor for data save
 *
 */
    struct DataSave_t{
        uint32_t bundrate;
        uint32_t flowControl;
        uint32_t dataBits;
        uint32_t parity;
        uint32_t stopBits;
        double joints[6][5];
        uint32_t canSendID[6];
        uint32_t canReceiveID[6];
        uint32_t canReceiveMASK[6];
        uint32_t canSendType[6];
        uint32_t canReceiveType[6];
    };



private slots:
    void on_btnJointSure_clicked();
    void on_btnSendSure_clicked();
    void on_btnReceiveSure_clicked();
    void on_btnXMoveAdd_pressed();
    void on_btnXMoveSub_pressed();
    void on_btnYMoveAdd_pressed();
    void on_btnYMoveSub_pressed();
    void on_btnZMoveAdd_pressed();
    void on_btnZMoveSub_pressed();
    void on_btnXRotateAdd_pressed();
    void on_btnXRotateSub_pressed();
    void on_btnYRotateAdd_pressed();
    void on_btnYRotateSub_pressed();
    void on_btnZRotateAdd_pressed();
    void on_btnZRotateSub_pressed();
    void on_btnJoint_1_Sub_pressed();
    void on_btnJoint_1_Add_pressed();
    void on_btnJoint_2_Add_pressed();
    void on_btnJoint_2_Sub_pressed();
    void on_tabWidget_tabBarClicked(int index);
    void on_pushButton_clicked();
    void on_btnJoint_3_Add_pressed();
    void on_btnJoint_3_Sub_pressed();
    void on_btnJoint_4_Add_pressed();
    void on_btnJoint_4_Sub_pressed();
    void on_btnJoint_5_Add_pressed();
    void on_btnJoint_5_Sub_pressed();
    void on_btnJoint_6_Add_pressed();
    void on_btnJoint_6_Sub_pressed();
    void on_serialReceived();
    void on_speedChanged(double);
    void on_btnRecord_clicked();
    void on_btnAction_clicked();
    void on_btnMoveTo_clicked();
    void on_btnRun_clicked();
    void on_btnRemoveAll_clicked();
    void on_btnDelete_clicked();
    void on_btnSearchProgram_clicked();
    void on_btnSaveProgram_clicked();
};
#endif // MAINWINDOW_H
